var t = getApp();

Page({
    data: {
        cond: !0,
        clause: [],
        clauselist: [],
        title: "合同",
        parties: "",
        parties2: "",
        preface: "",
        Signature: "",
        Oriclause: [ {
            keyword: "交易概述",
            keyname: "summary"
        }, {
            keyword: "甲方义务",
            keyname: "obliga"
        }, {
            keyword: "乙方义务",
            keyname: "obligb"
        }, {
            keyword: "丙方义务",
            keyname: "obligc"
        }, {
            keyword: "验收条款",
            keyname: "accept"
        }, {
            keyword: "违约责任",
            keyname: "liabity"
        }, {
            keyword: "免责事由",
            keyname: "execept"
        }, {
            keyword: "争议解决",
            keyname: "dispute"
        }, {
            keyword: "其他条款",
            keyname: "end"
        } ]
    },
    onLoad: function() {
        var t = wx.getStorageSync("title");
        t || (t = "合同");
        var e = wx.getStorageSync("parties"), n = e.c1;
        if (e && !n) {
            var a = "甲方：" + e.a1 + "\n地址：" + e.a2 + "\n证件号码：" + e.a3 + "\n\n乙方：" + e.b1 + "\n地址：" + e.b2 + "\n证件号码：" + e.b3 + "\n", r = "\n-------------以下为签署栏-------------\n\n甲方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年     月      日\n\n乙方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年    月      日\n";
            wx.removeStorage({
                key: "obligc"
            });
        }
        if (e && n) var a = "甲方：" + e.a1 + "\n地址：" + e.a2 + "\n证件号码：" + e.a3 + "\n\n乙方：" + e.b1 + "\n地址：" + e.b2 + "\n证件号码：" + e.b3 + "\n\n丙方：" + e.c1 + "\n地址：" + e.c2 + "\n证件号码：" + e.c3 + "\n", r = "-------------以下为签署栏-------------\n\n甲方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年     月      日\n\n乙方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年    月      日\n\n丙方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年    月      日\n";
        if (!e) var a = "甲方：\n地址：\n证件号码：\n\n乙方：\n地址：\n证件号码：\n", r = "\n-------------以下为签署栏-------------\n\n甲方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年     月      日\n\n乙方（盖章）：\n法定代表人（或代表人）签字：\n签署日期：     年    月      日\n";
        for (var i = wx.getStorageSync("preface"), o = this.data.Oriclause, c = 0, x = o.length; c < x; c++) o[c].text = wx.getStorageSync(o[c].keyname);
        o[1].text && o[1].text.length > 0 && (o[1].text = o[1].text.map(function(t) {
            return o[1].text.indexOf(t) + 1 + "、" + t + "\n";
        }).join("")), o[2].text && o[2].text.length > 0 && (o[2].text = o[2].text.map(function(t) {
            return o[2].text.indexOf(t) + 1 + "、" + t + "\n";
        }).join("")), o[3].text && o[3].text.length > 0 && (o[3].text = o[3].text.map(function(t) {
            return o[3].text.indexOf(t) + 1 + "、" + t + "\n";
        }).join("")), void 0 !== o[8].text && o[8].text.length > 0 && (o[8].text = o[8].text.map(function(t) {
            return o[8].text.indexOf(t) + 1 + "、" + t + "\n";
        }).join(""));
        for (var s = o.filter(function(t) {
            return t.text.length > 0 && void 0 !== t.text;
        }), d = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ], c = 0, x = s.length; c < x; c++) s[c].index = d[c];
        this.setData({
            clauselist: s,
            title: t,
            parties: e,
            parties2: a,
            preface: i
        }), wx.setStorageSync("parties2", a), wx.setStorageSync("Signature", r), wx.setStorageSync("clause", o);
    },
    backtotable: function() {
        wx.redirectTo({
            url: "../SdrafTable/SdrafTable"
        });
    },
    Lastsubmit: function(e) {
        for (var n = this.data.Oriclause, a = 0, r = n.length; a < r; a++) n[a].text = wx.getStorageSync(n[a].keyname);
        n[1].text && n[1].text.length > 0 && (n[1].text = n[1].text.map(function(t) {
            return t;
        }).join("【&#下一条：^//////】")), n[2].text && n[2].text.length > 0 && (n[2].text = n[2].text.map(function(t) {
            return t;
        }).join("【&#下一条：^//////】")), n[3].text && n[3].text.length > 0 && (n[3].text = n[3].text.map(function(t) {
            return t;
        }).join("【&#下一条：^//////】")), void 0 !== n[8].text && n[8].text.length > 0 && (n[8].text = n[8].text.map(function(t) {
            return t;
        }).join("【&#下一条：^//////】"));
        var i = this, o = wx.getStorageSync("title"), c = wx.getStorageSync("partAorB"), x = wx.getStorageSync("parties2"), s = wx.getStorageSync("preface"), d = wx.getStorageSync("userInfo"), l = n[0].text, u = n[1].text, g = n[2].text, S = n[3].text, y = n[4].text, m = n[5].text, p = n[6].text, f = n[7].text, w = n[8].text, h = wx.getStorageSync("Signature");
        wx.showToast({
            title: "保存中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/Smcontract/Smcontract/newContract",
            data: {
                formId: e.detail.formId,
                title: o,
                partAorB: c,
                parties: x,
                preface: s,
                summary: l,
                obliga: u,
                obligb: g,
                obligc: S,
                accept: y,
                liabity: m,
                execept: p,
                dispute: f,
                end: w,
                Signature: h,
                nickName: d.nickName,
                city: d.city,
                htbase: "S",
                htname: "合同",
                separator: "【&#下一条：^//////】"
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(t) {
                wx.hideToast();
                var e = t.data;
                if (t) {
                    e > 1 && (wx.showToast({
                        title: "保存成功",
                        icon: "success",
                        duration: 2e3
                    }), i.setData({
                        cond: !1,
                        addId: e
                    }));
                    for (var n = [ "title", "partAorB", "parties", "parties2", "preface", "summary", "obliga", "obligb", "obligc", "accept", "liabity", "execept", "dispute", "end", "Signature", "clause" ], a = 0, r = n.length; a < r; a++) wx.removeStorage({
                        key: n[a]
                    });
                }
            },
            fail: function(t) {
                wx.hideToast(), t && wx.showToast({
                    title: "保存失败无网络",
                    icon: "loading",
                    duration: 2600
                });
            }
        });
    },
    toExamMy: function(t) {
        wx.redirectTo({
            url: "../../pages/ExamMy/ExamMy?id=" + this.data.addId + "&htbase=SM"
        });
    },
    openContract: function(t) {
        this.data.Listurl, this.data.TopName, this.data.url, this.data.url2;
        var e = wx.getStorageSync("PHPSESSID");
        wx.redirectTo({
            url: "../../pages/MySht/MySht?id=" + this.data.addId + "&url=Smcontract/Smcontract/ContractDetail&url2=Smcontract/Smcontract/editContract&sessin=" + e + "&Listurl=Smcontract/Smcontract/&TopName=我起草的合同"
        });
    },
    toIndex: function(t) {
        wx.switchTab({
            url: "../Draft/Draft"
        });
    }
});